package com.jsyh.maidu.adapter.home;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.ImageView;

import java.util.ArrayList;

/**
 * Created by ZHY_9 on 2017/6/12.
 */

public class HomePagerAdapter extends PagerAdapter {

    private ArrayList<ImageView> viewList;

    public HomePagerAdapter(ArrayList<ImageView> viewList) {
        this.viewList = viewList;
    }



    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        position %= viewList.size();
        if (position < 0){
            position = viewList.size() + position;
        }
        ImageView view = viewList.get(position);
        ViewParent vp = view.getParent();
        if (vp != null){
            ViewGroup parent = (ViewGroup) vp;
            parent.removeView(view);
        }
        container.addView(view);

        return view;
    }
}
